package com.df.gamesynctest.net;

import com.df.gamesynctest.entity.Player;
import com.df.gamesynctest.msg.MsgWrapper;

import java.util.List;

public class MsgSend {
    public static void sendMsg(Player player,Object msg) {
        MsgWrapper msgWrapper = MsgWrapper.createMsgWrapper(msg);
        if(msgWrapper==null){
            return;
        }
        if(player.channel==null){
            return;
        }
        player.channel.writeAndFlush(msgWrapper.toByteBuff());
    }
    public static void broadMsg(List<Player> players, Object msg) {
        MsgWrapper msgWrapper = MsgWrapper.createMsgWrapper(msg);
        if(msgWrapper==null){
            return;
        }
        if(players==null || players.isEmpty()){
            return;
        }
        for (Player player : players) {
            if(player.channel==null){
                continue;
            }
            player.channel.writeAndFlush(msgWrapper.toByteBuff());
        }

    }
}
